﻿Imports System.Collections.Generic

Partial Class WebForm_ManageTrainingRegister_SearchVolunteerControl
    Inherits My.MyUserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Event OK_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        RaiseEvent OK_Click(Me, New EventArgs)

        Try
            Me.GridView_Volunteers.PageIndex = Me.GridView_Volunteers.PageIndex + 1
        Catch ex As Exception

        End Try

        Me.DoQuery()
        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_Volunteers_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_Volunteers.PageIndexChanged
        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_Volunteers_Sorted(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_Volunteers.Sorted
        Me.mpSearch.Show()
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        DoQuery()
        Me.mpSearch.Show()
    End Sub
    'Protected Sub cbCheckAll_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    '    Dim chkAll As CheckBox = TryCast(sender, CheckBox)

    '    For Each row As GridViewRow In Me.GridView_Volunteers.Rows
    '        Dim chk As CheckBox = TryCast(row.FindControl("CheckBox1"), CheckBox)

    '        chk.Checked = chkAll.Checked
    '    Next

    'End Sub
    Sub DoQuery()

        ObjectDataSource1.SelectParameters.Item("GroupId").DefaultValue = GroupId

        ObjectDataSource1.SelectParameters.Item("UOrganizationID").DefaultValue = VolunteerQueryControl1.OrganizationID
        'ObjectDataSource1.SelectParameters.Item("Region").DefaultValue = VolunteerQueryControl1.Region
        'ObjectDataSource1.SelectParameters.Item("Region2").DefaultValue = VolunteerQueryControl1.Region2
        ObjectDataSource1.SelectParameters.Item("VOrganizationID").DefaultValue = VolunteerQueryControl1.VOrganizationID
        ObjectDataSource1.SelectParameters.Item("VolunteerId").DefaultValue = VolunteerQueryControl1.VolunteerId
        ObjectDataSource1.SelectParameters.Item("VolunteerName").DefaultValue = VolunteerQueryControl1.VolunteerName
        ObjectDataSource1.SelectParameters.Item("TEL").DefaultValue = VolunteerQueryControl1.VolunteerTEL

        If Me.chkListNoBasic.Checked = True Then
            txtTrainingBHour.Text = MyObj.GetParameter("VBook", "BasicTrainingHour")
        Else
            txtTrainingBHour.Text = String.Empty
        End If

        If Me.chkListNoSpecial.Checked = True Then
            txtTrainingSHour.Text = MyObj.GetParameter("VBook", "SpecialTrainingHour")
        Else
            txtTrainingSHour.Text = String.Empty
        End If

        ObjectDataSource1.SelectParameters.Item("TrainingBHour").DefaultValue = IIf(txtTrainingBHour.Text = String.Empty, 0, txtTrainingBHour.Text)
        ObjectDataSource1.SelectParameters.Item("TrainingSHour").DefaultValue = IIf(txtTrainingSHour.Text = String.Empty, 0, txtTrainingSHour.Text)

        GridView_Volunteers.DataSourceID = ObjectDataSource1.ID
        GridView_Volunteers.DataBind()

    End Sub

End Class

Partial Class WebForm_ManageTrainingRegister_SearchVolunteerControl

    Public Sub InitDataAndShow()

        'chk_TrainingBHour.ValidationGroup = ValidationGroup
        'chk_TrainingSHour.ValidationGroup = ValidationGroup
        'btnQuery.ValidationGroup = ValidationGroup

        VolunteerQueryControl1.IsVolunteerLeader = IIf(Me.CanAdmin = False And Me.CanQuery = True, True, False)

        VolunteerQueryControl1.InitData()

        GridView_Volunteers.PageIndex = 0

        'txtTrainingBHour.Text = MyObj.GetParameter("VBook", "BasicTrainingHour")
        'txtTrainingSHour.Text = MyObj.GetParameter("VBook", "SpecialTrainingHour")

        'DoQuery()

        VolunteerQueryControl1.mpSearchUniqueID = mpSearch.UniqueID

        Me.mpSearch.Show()

    End Sub

    Public ReadOnly Property SelectedValues() As List(Of String)
        Get
            Dim Volunteers As New List(Of String)

            For Each row As GridViewRow In Me.GridView_Volunteers.Rows
                Dim key As DataKey = Me.GridView_Volunteers.DataKeys(row.RowIndex)

                If TryCast(row.FindControl("CheckBox1"), CheckBox).Checked = True Then
                    Volunteers.Add(key("VolunteerID"))
                End If
            Next

            Return Volunteers
        End Get
    End Property

    Public Property GroupId() As String
        Get
            Return ViewState("GroupId")
        End Get
        Set(ByVal value As String)
            ViewState("GroupId") = value
        End Set
    End Property

    Public Property ValidationGroup() As String
        Get
            Return ViewState("ValidationGroup")
        End Get
        Set(ByVal value As String)
            ViewState("ValidationGroup") = value
        End Set
    End Property


End Class
